<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<html><o:MultiLanguage>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/dialog.css" type="text/css">
<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />' type="text/css">
<script src='<ww:url value="/dwr/interface/ConfigUtil.js"/>'></script>
<script src='<ww:url value="/dwr/interface/DWRHtmlUtil.js"/>'></script>
<script src='<ww:url value="/dwr/interface/ApplicationUtil.js"/>'></script>
<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>

<script language=JavaScript src="../include/utility.js"></script>
<script language=JavaScript src="../../dialog/sequence.js"></script>

<script language=JavaScript src="dialog/dialog.js"></script>
<script language=JavaScript src="dialog/script.js"></script>
<script src="../../dialog/common/fck_dialog_common.js" type="text/javascript"></script>
<link href="../../css/dialog.css" rel="stylesheet" type="text/css" />

<script language=JavaScript>
var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded();
// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument;
var oActiveEl = dialog.Selection.GetSelectedElement();

function getCreateNamedElement() {
	var className = "cn.myapps.core.dynaform.form.ejb.IncludeField";

	var id = oActiveEl ? oActiveEl.id: getFieldId();
	//alert(createRelStr());
	// HTMLEncode引用至util.js
	var str = temp.hiddenScript.value;
	return CreateNamedElement(
		oEditor, oActiveEl, 'img', {
		src:"plugins/includefield/includefield.gif",
		classname: className,
		id: id,
		includeType: temp.includeType.value,
		refreshOnChanged: HTMLEncode(temp.refreshOnChanged.checked+""),
		calculateOnRefresh:HTMLEncode(temp.calculateOnRefresh.checked+""),
		enabled: HTMLEncode(temp.enabled.checked+""),
		valueScript: HTMLEncode(temp.valueScript.value),
		hiddenScript:HTMLEncode(temp.hiddenScript.value),
		hiddenValue:HTMLEncode(temp.hiddenValue.value),//////
		module: HTMLEncode(temp.module.value),
		viewid: HTMLEncode(temp.viewid.value),
		pageid: HTMLEncode(temp.pageid.value),
		name: HTMLEncode(temp.name.value),
		relate: HTMLEncode(temp.relate.checked+"")
	});
}

//选项卡点击事件
function cardClick(cardID){
	var obj;
	for (var i=1;i<3;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";
	
	for (var i=1;i<3;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";
}


// {*[Click exit]*}
function Ok(){	
	if(ev_check()){
		if( document.getElementsByName("includeType")[0].value=="0"){
			
			if(temp.module.value=="none"){
				alert("{*[page.includefield.module]*}");
			    return false;
			}
			if(temp.viewid.value=="none"){
				alert("{*[page.includefield.view]*}");
			    return false;
				}
		}
		oEditor.FCKUndo.SaveUndoStep() ;
		//检查内容是否完成正确
		oActiveEl = getCreateNamedElement();
		return true;
	}
}

// {*[Initial value]*}
function InitDocument(){
	// {*[Get value when modifying status]*}
	if (oActiveEl){
		var tmp = oActiveEl.valueScript;
		var tval = oActiveEl.includeType;
		temp.refreshOnChanged.checked = oActiveEl.refreshOnChanged == "true";
		temp.calculateOnRefresh.checked = oActiveEl.calculateOnRefresh == "true";
		temp.enabled.checked = oActiveEl.enabled == "true";
		temp.relate.checked = oActiveEl.relate == "true";
		
		if(tmp!=null){
			temp.valueScript.value = HTMLDencode(tmp);
		}
		
		temp.includeType.value = tval;
		
		if(oActiveEl.hiddenScript!=null){
			temp.hiddenScript.value = HTMLDencode(oActiveEl.hiddenScript);
		}

		if(oActiveEl.hiddenValue!=null){
			temp.hiddenValue.value = HTMLDencode(oActiveEl.hiddenValue);
		}
		
		ev_setVal(temp.module, oActiveEl.module);
		ev_setVal(temp.viewid, oActiveEl.viewid);
		ev_setVal(temp.pageid, oActiveEl.pageid);
		temp.name.value = oActiveEl.name;
	}
	
	ev_init();
	
	dialog.SetOkButton( true ) ;
	dialog.SetAutoSize( true ) ;
	SelectField( 'name' ) ;
	window.top.toThisHelpPage("application_module_form_info_advance_include");
}

function ev_setVal(el, val) {
	if (el) {
		var opt = document.createElement("OPTION");
		opt.value = val;
		opt.selected = true;
		el.add(opt);
	}
}

function ev_onchange(val) {
	val='"'+val+'"';
	temp.valueScript.value=val;
	
}

function ev_select(module,view,page) {
	var av = '<ww:property value="#parameters.application" />'
	var mv = document.getElementsByName(module)[0].value;
	var vv = document.getElementsByName(view)[0].value;
	var pv = document.getElementsByName(page)[0].value;
	
	if (document.getElementsByName(module)[0].value=='none') {
		vv = 'none';
		pv = 'none';
	}
	
	var func = new Function("ev_select('"+module+"','"+view+"','"+page+"')");
	document.getElementsByName(module)[0].onchange = func;
	
	ApplicationUtil.creatModule(module,av,mv,function(str) {var func=eval(str);func.call()});
	ApplicationUtil.creatView(view,av,mv,vv,function(str) {var func=eval(str);func.call()});
	ApplicationUtil.creatPage(page,av,pv,function(str) {var func=eval(str);func.call()});
}

function ev_init() {
	var type = document.getElementsByName("includeType")[0];
	var func = new Function("ev_showElems(this.value);document.getElementsByName('valueScript')[0].value='';");
	type.onchange = func;
	ev_showElems(type.value);
}

function ev_showElems(type) {
	if (document.getElementsByName("module")[0].options[0]) {
		document.getElementsByName("module")[0].options[0].selected = true;
	}
	
	ev_select('module','viewid','pageid');
	if (type != null && type != '') {
		type == '0' ? viwtr.style.display = '' : viwtr.style.display = 'none';
		type == '0' ? moduletr.style.display = '' : moduletr.style.display = 'none';
		type == '1' ? pagtr.style.display = '' : pagtr.style.display = 'none';
	}
}
function ev_check(){
	if(temp.name.value==''){
	 	alert("{*[page.name.notexist]*}");
		return false;
	}
  	return !checkStartChar(temp.name.value);
}

function checkStartChar(value){
	return IsDigit(value,"{*[page.name.startingit]*}");
}
function IsDigit(s,msg){
	var text = s.substring(0,1);
	var patrn=/^[0-9]{1}$/; 
	if(s=="action"){
	   	alert("action为关键字，不能作为字段名！");
	   	return true;
   	}else if (patrn.exec(text)){
		alert(msg);
		return true;
	}
	return false;
}  
</script>
</head>
<body bgcolor="menu"  onload="InitDocument()">
<ww:form name="temp" method="post" theme="simple">
<table border=0 cellpadding=3 cellspacing=0 width="520px">
			<tr align=center>
				<td class="card" onclick="cardClick(1)" id="card1">{*[Basic]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(2)" id="card2">{*[Hidden_Script]*}</td>
				<td width=2></td>
			</tr>
			<tr>
				<td valign=middle colspan=12 bgcolor=#ffffff align=center
					width="100%">
				<table border=1 cellpadding=3 cellspacing=1  class="content" id="content1" bgcolor=#ffffff width="520px" height="250px">

					<tr>
						<td class="commFont commLabel">{*[Name]*}:</td>
						<td><ww:textfield name="name" id="name" cssStyle="width:200"/></td>
					</tr>
					
					<tr>
						<td class="commFont commLabel">{*[IncludeType]*}:</td>
						<td><ww:select cssClass="input-cmd" name="includeType" list="#{'0':'View','1':'HomePage'}" cssStyle="width:200"/></td>
					</tr>
					
					<tr id="moduletr">
						<td class="commFont commLabel">{*[Module]*}:</td>
						<td><ww:select  cssClass="input-cmd" name="module" list="{}" cssStyle="width:200"/></td>
					</tr>
								
					<tr id="viwtr">
						<td class="commFont commLabel">{*[View]*}:</td>
						<td><ww:select  cssClass="input-cmd" name="viewid" list="{}" cssStyle="width:200" onchange="ev_onchange(this.value)"/></td>
					</tr>
					
					<tr id="pagtr">
						<td class="commFont commLabel">{*[HomePage]*}:</td>
						<td><ww:select  cssClass="input-cmd" name="pageid" list="{}" cssStyle="width:200" onchange="ev_onchange(this.value)"/></td>
					</tr>
					
					<tr>
						<td colspan="2" align="center">
							<input type=checkbox name="relate" value="true" checked="checked">{*[IsRelate]*}&nbsp;
							<input type=checkbox name="refreshOnChanged" value="true">{*[Refresh]*}&nbsp;
							<input type=checkbox name="calculateOnRefresh" value="true">{*[Recalculate]*}&nbsp;
							<div style="display:none">
							<input type=checkbox name="enabled" value="true">{*[ShowView]*}&nbsp;
							</div>
						</td>
					</tr>
					
					<tr style="display:none">
						<td colspan=2  align="center">
						  <textarea name="valueScript"  readonly="readonly" cols="50" rows="10" style="width:96%"></textarea>
						  <button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('valueScript','{*[Script]*}{*[Editor]*}','{*[Value_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
				</table>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content2">
					<tr>
						<td><textarea name="hiddenScript" style="width:96%" rows="10"></textarea>
						<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
					<tr>
						<td>{*[hiddenValue]*}：<input id="hiddenValue" type="text" name="hiddenValue" /></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
</ww:form>
<script language=javascript>
cardClick(1);
</script>
</BODY>
</o:MultiLanguage>
</HTML>
